package dt.board.notice;
import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.io.Reader;
import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.SessionAware;

public class noticeModifyAction extends ActionSupport implements SessionAware{
	private Map session;
	
	public static Reader reader;
	public static SqlMapClient sqlMapper;

	private noticeBoardVO paramClass; //파라미터를 저장할 객체
	private noticeBoardVO resultClass; //쿼리 결과 값을 저장할 객체

	private int currentPage;	//현재 페이지
	
	private int no;
	private String subject;
    private String content;
    private String password; 



	// 생성자
	public noticeModifyAction() throws IOException {
		
		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); // sqlMapConfig.xml 파일의 설정내용을 가져온다.
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); // sqlMapConfig.xml의 내용을 적용한 sqlMapper 객체 생성.
		reader.close();
	}

	// 게시글 수정
	public String execute() throws Exception {
		
		//파라미터와 리절트 객체 생성.
		paramClass = new noticeBoardVO();
		resultClass = new noticeBoardVO();

		// 수정할 항목 설정.
		paramClass.setNo(getNo());
		paramClass.setSubject(getSubject());
		paramClass.setPassword(getPassword());
		paramClass.setContent(getContent());

		// 일단 항목만 수정한다.
		sqlMapper.update("notice.updateBoard", paramClass);

		// 수정이 끝나면 view 페이지로 이동.
		resultClass = (noticeBoardVO) sqlMapper.queryForObject("notice.selectOne", getNo());

		return SUCCESS;
	}

	public noticeBoardVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(noticeBoardVO paramClass) {
		this.paramClass = paramClass;
	}

	public noticeBoardVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(noticeBoardVO resultClass) {
		this.resultClass = resultClass;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}
}